package com.gpframework.module.controller.module;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.gpframework.common.exception.ParamException;
import com.gpframework.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.module.domain.GpGramWeight;
import com.gpframework.module.module.domain.vo.GpGramWeightVo;
import com.gpframework.module.module.domain.req.GpGramWeightReq;
import com.gpframework.module.module.domain.req.GpGramWeightAdd;
import com.gpframework.module.module.domain.req.GpGramWeightUpdate;
import com.gpframework.module.module.service.IGpGramWeightService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpGramWeightController
 * @Author gpframework
 * @Date 2023-12-11
 * @Version 1.0.0
 * @Description 克重Controller 接口类
 */
@Validated
@Api(tags = "克重")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/module/gramweight" )
public class GpGramWeightController extends BaseController {

    private final IGpGramWeightService iGpGramWeightService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-12-11
  * @Param gpGramWeight
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @GetMapping("/list")
    public TableDataInfo<GpGramWeightVo> list(GpGramWeightReq gpGramWeightReq)
    {
        startPage();
        QueryWrapper<GpGramWeight> lqw = new QueryWrapper<GpGramWeight>();
        gpGramWeightReq.generatorQuery(lqw,true);
        List<GpGramWeightVo> list = iGpGramWeightService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpGramWeight
     * @Return AjaxResult
     */
    @ApiOperation("详情")
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpGramWeightVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpGramWeightService.getVoById(id));
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpGramWeight
     * @Return AjaxResult
     */
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpGramWeightAdd gpGramWeightAdd) {
        GpGramWeight gpGramWeight = Convert.convert(new TypeReference<GpGramWeight>() {}, gpGramWeightAdd);
        return toAjax(iGpGramWeightService.save(gpGramWeight) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpGramWeight
     * @Return AjaxResult
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpGramWeightUpdate gpGramWeightUpdate) {
        GpGramWeight gpGramWeight = Convert.convert(new TypeReference<GpGramWeight>() {}, gpGramWeightUpdate);
        return toAjax(iGpGramWeightService.updateById(gpGramWeight) ? 1 : 0);
    }

    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-12-11
     * @Param gpGramWeight
     * @Return AjaxResult
     */
    @ApiOperation("删除")
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpGramWeightService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
